<?
	include "db.php";
	$files = array();
	$docs = array();
	$i = 0;
	$output = "
USE phpdoc;
DROP TABLE IF EXISTS docs;
CREATE TABLE `docs` (`id` int(5) NOT NULL auto_increment, `name` varchar(50) NOT NULL, `file` varchar(100) NOT NULL, `text` text NOT NULL, PRIMARY KEY  (`id`), KEY `NAME` (`name`), FULLTEXT KEY `text` (`text`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";

	$dir = opendir("./html/");
	while ($file = readdir($dir)) 
	{
		if (!is_dir("./html/" . $file)) 
		{
			$files[] = $file;
			$i++;
		}
	}
	closedir($dir);
	foreach ($files as $filename)
	{
		$contents = mysql_real_escape_string(file_get_contents("./html/" . $filename), $connection);
		$nameparts = explode(".", $filename);
		array_pop($nameparts);
		$name = implode(" ", explode("-", implode(" ", $nameparts)));
		$query = "INSERT INTO docs SET id=NULL, name='{$name}', file='{$filename}', text='{$contents}';";
		$output .= $query . "\n";
		//echo $i, "\n"; $i--;
	}
	
	header("Content-type: application/force-download");
	header('Content-Disposition: inline; filename="output.sql"');
	header("Content-Transfer-Encoding: Binary");
	header("Content-length: ".strlen($output));
	header('Content-Type: application/octet-stream');
	print $output;
?>